package admin

import "object/go_cms/models"

type ArticleController struct {
	BaseAdminController
	models models.ArticleModels
}

/**
文章管理
*/
// @router /admin/article/indexUI [get]
func (c *ArticleController) IndexUI() {
	c.TplAdmin("article/index")
}

// @router /admin/article/addUI [get]
func (c *ArticleController) AddUI() {
	c.TplAdmin("article/add")
}

// @router /admin/article/editUI [get]
func (c *ArticleController) EditUI() {
	c.TplAdmin("article/edit")
}

// @router /admin/article/get [get,post]
func (c *ArticleController) Get() {
	c.Res.Code = 1
	id, _ := c.GetInt64("id")
	c.Res.Data, _ = c.models.Get(id)
	c.Json(c.Res)
}

// @router /admin/article/query [post]
func (c *ArticleController) Query() {
	c.Res.Code = 0
	maps := c.GetParamMap()
	c.Res.Data, c.Res.Count, _ = c.models.QueryByPage(maps)
	c.Json(c.Res)
}

// @router /admin/article/add [post]
func (c *ArticleController) Add() {
	c.Res.Code = 1
	c.Res.Msg = "添加成功"
	maps := c.GetParamMap()
	_, err := c.models.Add(maps)
	if err != nil {
		c.Res.Code = 0
		c.Res.Msg = err.Error()
	}
	c.Json(c.Res)
}

// @router /admin/article/edit [post]
func (c *ArticleController) Edit() {
	c.Res.Code = 1
	c.Res.Msg = "修改成功"
	maps := c.GetParamMap()
	_, err := c.models.Update(maps)
	if err != nil {
		c.Res.Code = 0
		c.Res.Msg = err.Error()
	}
	c.Json(c.Res)
}

// @router /admin/article/delete [post]
func (c *ArticleController) Delete() {
	c.Res.Code = 1
	c.Res.Msg = "删除成功"
	id, _ := c.GetInt64("id")
	_, err := c.models.Delete(id)
	if err != nil {
		c.Res.Code = 0
		c.Res.Msg = err.Error()
	}
	c.Json(c.Res)
}
